package top.eggcode.component.dingtalk;

public class DingMessage {
    public MessageAt at;

    public Object text;

    public Object markdown;

    public String msgtype;

    public static Builder builder() {

        Builder builder = new Builder();
        builder.message = new DingMessage();
        return builder;
    }


    public static class Builder {

        private DingMessage message;

        private MessageAt at;

        private Builder() {
        }


        public DingMessage.Builder setTextContent(String text) {
            TextBody messageBody = new TextBody();
            messageBody.content = text;
            message.text = messageBody;
            message.msgtype = "text";

            return this;
        }

        public DingMessage.Builder setMarkdownContent(String title, String text) {
            MarkdownBody markdownBody = new MarkdownBody();
            markdownBody.title = title;
            markdownBody.text = text;
            message.msgtype = "markdown";
            message.markdown = markdownBody;
            return this;
        }

        public DingMessage.Builder atMobile(String number) {
            if (at == null) {
                at = new MessageAt();
            }
            at.atMobiles.add(number);
            return this;
        }

        public DingMessage.Builder atALl() {
            if (at == null) {
                at = new MessageAt();
            }
            at.isAtAll = true;
            return this;
        }

        public DingMessage.Builder atUserId(String id) {
            if (at == null) {
                at = new MessageAt();
            }
            at.atUserIds.add(id);
            return this;
        }

        public DingMessage toMessage() {
            if (at != null) {
                message.at = at;
            }
            return message;
        }
    }
}
